<page-header model="ctrl.navModel"></page-header>

<div class="page-container page-body">

  <div ng-if="ctrl.current.readOnly"  class="page-action-bar">
    <div class="grafana-info-box span8">
      免责声明。此数据源是由配置添加的，无法通过 UI 进行修改。请联系您的服务器管理员以更新此数据源。
    </div>
  </div>

  <form name="ctrl.editForm" ng-if="ctrl.current">
    <div class="gf-form-group">
      <div class="gf-form-inline">
        <div class="gf-form max-width-30">
          <span class="gf-form-label width-7">名称</span>
          <input class="gf-form-input max-width-23" type="text" ng-model="ctrl.current.name" placeholder="名称" required>
          <info-popover offset="0px -135px" mode="right-absolute">
            当您在面板中选择数据源时使用该名称。
            在新面板中预先选择 <em>默认的</em> 数据源。
          </info-popover>
        </div>
        <gf-form-switch class="gf-form" label="默认" checked="ctrl.current.isDefault" switch-class="max-width-6"></gf-form-switch>
      </div>

      <div class="gf-form">
        <span class="gf-form-label width-7">类型</span>
        <div class="gf-form-select-wrapper max-width-23">
          <select class="gf-form-input" ng-model="ctrl.current.type" ng-options="v.id as v.name for v in ctrl.types" ng-change="ctrl.userChangedType()"></select>
        </div>
      </div>
    </div>

    <div class="alert alert-info gf-form-group" ng-if="ctrl.datasourceMeta.state === 'alpha'">
      此插件标记为处于 Alpha 状态，这意味着它处于早期开发阶段，而更新可能会包含破坏性变更。
    </div>

    <rebuild-on-change property="ctrl.datasourceMeta.id">
      <plugin-component type="datasource-config-ctrl">
      </plugin-component>
    </rebuild-on-change>

    <div ng-if="ctrl.hasDashboards">
      <h3 class="section-heading">捆绑的插件仪表板</h3>
      <div class="section">
        <dashboard-import-list plugin="ctrl.datasourceMeta" datasource="ctrl.current"></dashboard-import-list>
      </div>
    </div>

    <div ng-if="ctrl.testing" class="gf-form-group section">
      <h5 ng-show="!ctrl.testing.done">测试中…… <i class="fa fa-spiner fa-spin"></i></h5>
      <div class="alert-{{ctrl.testing.status}} alert" ng-show="ctrl.testing.done">
        <div class="alert-icon">
          <i class="fa fa-exclamation-triangle" ng-show="ctrl.testing.status === 'error'"></i>
          <i class="fa fa-check" ng-show="ctrl.testing.status !== 'error'"></i>
        </div>
        <div class="alert-body">
          <div class="alert-title">{{ctrl.testing.message}}</div>
        </div>
      </div>
    </div>

    <div class="gf-form-button-row">
      <button type="submit" class="btn btn-success" ng-disabled="ctrl.current.readOnly"  ng-click="ctrl.saveChanges()">保存 &amp; 测试</button>
      <button type="submit" class="btn btn-danger" ng-disabled="ctrl.current.readOnly"  ng-show="!ctrl.isNew" ng-click="ctrl.delete()">
        删除
      </button>
      <a class="btn btn-inverse" href="datasources">返回</a>
    </div>

    <br />
    <br />
    <br />

  </form>
</div>
